//
//  MainRefreshBezierPathV.m
//  ZITHER
//
//  Created by weixin on 2018/8/28.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "MainRefreshBezierPathV.h"

@implementation MainRefreshBezierPathV

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [UIColor setDefaulGradiennBackgroundColors:self];

//        self.backgroundColor = baseColorRepainting;
        [self setCornerRadiusWithRadius:self.frame.size.width/2.0 isMasks:YES];
        
        UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(self.frame.size.width/4.0, self.frame.size.width/4.0, self.frame.size.width/2.0, self.frame.size.height/2.0)];
//        image.center = self.center;
        image.image = [UIImage imageNamed:@"sku_btn_fresh"];
        image.contentMode = UIViewContentModeScaleAspectFill;
        [self addSubview:image];
    }
    return self;
}
-(void)drawRect:(CGRect)rect{



    //    定义扇形中心
    CGPoint origin = CGPointMake(self.frame.size.width/2.0, self.frame.size.width/2.0);
    //    定义扇形半径
    CGFloat radius = 100.0f;

    //    设定扇形起点位置
    CGFloat startAngle = - M_PI_2;
    //    根据进度计算扇形结束位置
    CGFloat endAngle = startAngle + self.radius/24.0 * M_PI * 2;

    //    根据起始点、原点、半径绘制弧线
    UIBezierPath *sectorPath = [UIBezierPath bezierPathWithArcCenter:origin radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES];

    //    从弧线结束为止绘制一条线段到圆心。这样系统会自动闭合图形，绘制一条从圆心到弧线起点的线段。
    [sectorPath addLineToPoint:origin];

    //    设置扇形的填充颜色
    [baseColorLight set];
    self.backgroundColor = baseColorRepainting;


    //    设置扇形的填充模式
    [sectorPath fill];


}

-(void)setRadius:(long)radius{
    
    _radius = radius;
    
    if (radius>23) {
        self.backgroundColor =  baseColorGradientL;
        self.userInteractionEnabled = YES;
        _radius = 0;
    }else{
        self.backgroundColor = baseColorRepainting;
        self.userInteractionEnabled = NO;
    }
    [self setNeedsDisplay];

}




@end
